/**
  ******************************************************************************
  * @file    nuc it.c
  * @brief   Interrupt Service Routines.
  ******************************************************************************
**/
#include "common.h"
#include "ledctr.h"
#include "os_obj.h"
#include "mbapp.h"
#include "systask.h"
#include "com_obj.h"

/*
*********************************************************************************************************
*                                        TICK HOOK (APPLICATION)
*
* Description : This function is called every tick.
*
* Argument(s) : none.
*
* Note(s)     : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/

void GuiTick(void);
void os_tick_hook(void)
{
    //uTick+=1000/OS_CFG_TICK_RATE_HZ;
    //GuiTick();
    led_ctr_scan();
}


/*
*********************************************************************************************************
*                                        app tick
* Description : This function is irq isr.
*
* Argument(s) : none.
*
*********************************************************************************************************
*/
void mb01_dir_handle(void);
void mb02_dir_handle(void);
void mb03_dir_handle(void);
void ts_task(void);

void ETMR2_IRQHandler(void)
{
    outpw(REG_ETMR2_ISR, 1);
    sys_run_st.uTick++;
    //mb_rtu_timer_run(&mb.obj01);
    mb_rtu_timer_run(&mb.obj02);
    mb_rtu_timer_run(&mb.obj03);
    //mb01_dir_handle();
    mb02_dir_handle();
    mb03_dir_handle();
    
    com.obj00.fun->timer_handle();
    com.obj01.fun->timer_handle();
}

/*
*********************************************************************************************************
*                                         t 
* Description : This function is irq isr.
*
* Argument(s) : none.
*
*********************************************************************************************************
*/
void ETMR3_IRQHandler(void)
{
    outpw(REG_ETMR3_ISR, 1);
}

/*
*********************************************************************************************************
*                                         
* Description : This function is irq isr.
*
* Argument(s) : none.
*
*********************************************************************************************************
*/
void TIMER_IRQHandler(void)
{
    uint16_t IntSt;
    
    IntSt = inps(REG_TMR_TISR);
    
    /*timer0 isr*/
    if(IntSt & 0x01)
    {
        outpw(REG_TMR_TISR, 0x01);
    }
    
    /*timer1 isr*/
    if(IntSt & 0x02)
    {
        outpw(REG_TMR_TISR, 0x02);
    }
    
    /*timer2 isr*/
    if(IntSt & 0x04)
    {
        outpw(REG_TMR_TISR, 0x04);
    }
    
    /*timer3 isr*/
    if(IntSt & 0x08)
    {
        outpw(REG_TMR_TISR, 0x08);
    }
}

/*
*********************************************************************************************************
*                                         
* Description : This function is irq isr.
*
* Argument(s) : none.
*
*********************************************************************************************************
*/
void PWM_IRQHandler(void)
{
    uint16_t IntSt;
    
    IntSt = inps(REG_PWM_PIER) & inps(REG_PWM_PIIR);
    
    /*pwm0 isr*/
    if(IntSt & 0x01)
    {
        outpw(REG_PWM_PIIR, 0x01);
    }
    
    /*pwm1 isr*/
    if(IntSt & 0x02)
    {
        outpw(REG_PWM_PIIR, 0x02);
    }
    
    /*pwm2 isr*/
    if(IntSt & 0x04)
    {
        outpw(REG_PWM_PIIR, 0x04);
    }
    
    /*pwm3 isr*/
    if(IntSt & 0x08)
    {
        outpw(REG_PWM_PIIR, 0x08);
    }
}
